package cn.le.inf;

import cn.le.entty.User;
import org.apache.ibatis.annotations.*;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.cache.annotation.Cacheable;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {

    @Results({
            @Result(property = "name",column = "u_name"),
            @Result(property = "age",column = "u_age")
    })

    @Cacheable(value = "bigdata:metadata:cache:MdDataSource")
    @Select("select u_name name,u_age age from md_user")
    List<SecurityProperties.User> findUser();

    @Cacheable
    @Select("select u_name name,u_age age from md_user")
    @ResultType(value = HashMap.class)
    List<Map<String,Object>> findMap();

    @Insert("insert into md_user(u_name,u_age)values(#{name},#{age})")
    int insert(@Param("name") String name, @Param("age") Integer age);

    @Insert("insert into md_user(u_name,u_age)values(#{name},#{age})")
    int insertMap(Map<String, Object> map);

    @Update("update md_user set u_age = #{age} where u_name = #{name}")
    int update(User user);

    @Delete("delete from md_user where u_name = #{name}")
    int delete(User user);
}
